package clientresponse;

import clientcore.Question;
import java.io.IOException;


public class ResponseBoardQuestion extends ResponseFromServer {
    private int duration;
    private short questionid;
    private String username,lastname;
    public Question question;

    @Override
    public void process() {
        try {
            //duration = (int)inFromServer.readByte();
            duration = (int)((inFromServer.readByte()& 0xFF)+(inFromServer.readByte()<< 8)+(inFromServer.readByte()<< 16)+(inFromServer.readByte()<< 24));
            System.out.println("The duration is: "+duration);
            questionid = (short)((inFromServer.readByte()& 0xFF)+(inFromServer.readByte()<< 8));
            System.out.println("The questionid is: "+questionid);
            question = new Question(questionid);
            question.setType((short)((inFromServer.readByte()& 0xFF)+(inFromServer.readByte()<< 8)));

            int length = (int)((inFromServer.readByte()& 0xFF)+(inFromServer.readByte()<< 8));
            byte[]b = new byte[length];
            inFromServer.read(b,0,length);
            String topic = new String(b,0,length);
            question.setTopic(topic);
            System.out.println("The topic is: "+topic);

            length = (int)((inFromServer.readByte()& 0xFF)+(inFromServer.readByte()<< 8));
            b = new byte[length];
            inFromServer.read(b,0,length);
            String text = new String(b,0,length);
            question.setText(text);
            System.out.println("The text is: "+text);

            length = (int)((inFromServer.readByte()& 0xFF)+(inFromServer.readByte()<< 8));
            b = new byte[length];
            inFromServer.read(b,0,length);
            String options = new String(b,0,length);
            question.setAllOptions(options);
            System.out.println("The options are: "+options);


            length = (int)((inFromServer.readByte()& 0xFF)+(inFromServer.readByte()<< 8));
            b = new byte[length];
            inFromServer.read(b,0,length);
            String status = new String(b,0,length);
            //question.setStatus(status);
            System.out.println("The status is: "+status);


            length = (int)inFromServer.readByte();
            inFromServer.readByte();
            b = new byte[length];
            inFromServer.read(b,0,length);
            System.out.println("The status is: "+new String(b,0,length));


        } catch (IOException ex) {
            System.out.println("IO Exception in class ResponseLogin in method process()");
        }

    }



}
